<%@ tag language="java" pageEncoding="ISO-8859-1"%>
<%@ attribute name="pagesize" required="true"%>
<%@ tag import="java.util.Date" 
		import="java.text.DateFormat"
		import="java.util.List" 
		import="ro.k.web.beans.order.ManoperaBaseBean"%>
		
<jsp:useBean id="tagCmdMan" class="ro.k.tags.ComandaManopera" scope="session" />

<script type="text/javascript" src="../js/xmlObj.js"></script>
<script type="text/javascript" src="../js/updateCantMan.js"></script>

<%
	final String PAGE_PARAM = "pc";
	final String SORT_PARAM = "s";
	final String REM_PARAM = "rm";

	int currPage = ro.k.web.beans.KBeanUtils.pageNr(request
			.getParameter(PAGE_PARAM));
	int pgsize = Integer.parseInt(pagesize);

	List<ManoperaBaseBean> li = tagCmdMan.getManComanda();
	String page = request.getRequestURI().substring(
			request.getRequestURI().lastIndexOf("/") + 1);
	tagCmdMan.removeMan(request.getParameter(REM_PARAM));

	int nrPages = li.size() / pgsize;
	if (li.size() % pgsize != 0 || nrPages == 0) {
		nrPages++;
	}
%>
<div style="margin-top: 15px; margin-bottom: 10px">
<font style="margin-right: 5px">Manopera adaugata</font>
</div>

<table id="manServiceTable">
	<thead>
		<tr bgcolor="#CBF5E8">
			<th width="45px;">Cod</th>
			<th width="300px;">Nume</th>
			<th width="60px">Valoare</th>
			<th width="48px">Cant.</th>
			<th width="60px">Total</th>
			<th width="37px">&nbsp;</th>
		</tr>
	</thead>
	<tbody>
		<%
			//regularizare culori, prima sa fie alba
			int i = (currPage - 1) * pgsize;
			int rowc = (i % 2) == 0 ? 1 : 0;

			for (; i < currPage * pgsize; i++) {
				if (i >= li.size()) {
		%>
		<tr <%out.print(((i + rowc) % 2 == 0) ? "" : "class=\"imp\" ");%>
			style="height: 26px;">
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		<%
			} else {
		%>
		<tr <%out.print(((i + rowc) % 2 == 0) ? "" : "class=\"imp\"");%>>
			<%
				String icod = li.get(i).getCod();
				String ival = li.get(i).getValoare();
				Double icant = li.get(i).getCant();
			%>
			<td><%=icod%></td>
			<td><%=li.get(i).getNume()%></td>
			<td align="right">
				<input type="hidden" value="<%=ival%>" id="inH<%=icod%>" /> 
				<span id="sValue<%=icod%>"><%=ival%></span>
			</td>
			<td align="right">
				<!-- valoare veche, inainte de submit --> 
				<input type="hidden" value="<%=icant%>" id="oldV<%=icod%>" /> 
				<!-- ajax update server si UI, pentru cantitate -->
				<input type="text" style="width: 40px; text-align: right;"
				onblur="ajaxFunction(this);" value="<%=icant%>" name="<%=icod%>" />
			</td>
			<td align="right">
				<span id="sTotal<%=icod%>"><%=li.get(i).getTotal()%></span>
			</td>
			<td><a href="<%=page + "?"+REM_PARAM+"=" + icod%>">sterge</a></td>
		</tr>
		<%
			}
			}
		%>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="4" align="center" width="80%">
				<table>
					<tr>
						<td width="33%">
							<%	if (currPage > 1) {	%> 
									<a href="<%=page + "?" + PAGE_PARAM + "=1"%>">&lt;&lt; Prima</a> 
									<a href="<%=page + "?" + PAGE_PARAM + "=" + (currPage - 1)%>">&lt; Inapoi</a> 
							<%	}%>
						</td>
						
						<td width="<%=(nrPages == 1) ? 40 : 32%>%" align="center">
						<% out.println("Pagina " + currPage + " din " + nrPages);%></td>
						
						<td width="35%">
							<%	if (currPage < nrPages) { %> 
									<a href="<%=page + "?" + PAGE_PARAM + "=" + (currPage + 1)%>">Inainte &gt;</a>
									<a href="<%=page + "?" + PAGE_PARAM + "=" + nrPages%>">Ultima &gt;&gt;</a> 
							<%	}	%>
						</td>
					</tr>
				</table></td>
			<td align="right"><span id="sListTotal">
			<%=tagCmdMan.getManComanaTotal()%></span>
			</td>
			<td width="37px">&nbsp;</td>
		</tr>
	</tfoot>
</table>